package com.xiedafeng.www.view;

import com.xiedafeng.www.controller.CircleController;
import com.xiedafeng.www.po.Circle;
import com.xiedafeng.www.po.User;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class CreateCircleView {
    TextField circleName =new TextField();
    Stage stage=new Stage();
    public void createView(User user){
        Text tip=new Text("请输入瓜圈名");
        Button confirm=new Button("创建");
        GridPane gridPane=new GridPane();
        gridPane.add(tip,0,0);
        gridPane.add(circleName,0,1);
        gridPane.add(confirm,0,2);
        confirm.setOnMouseClicked(event -> {
            try {
                confirmButton(user);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        Scene scene=new Scene(gridPane);
        stage.setScene(scene);
        stage.showAndWait();
    }
    private void confirmButton(User user) throws Exception {
        Circle circle = new Circle();
        circle.setCircleName(circleName.getText());
        CircleController circleController=new CircleController();
        circleController.createCircle(user,circle);
    }
}
